#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

/*
//regular way
struct student_info{
    char name[101];
    int age;
    int score;
}data[1000];

bool cmp(student_info a, student_info b);

int main(int argc, char const *argv[]){
    int n;
    while(cin >> n){
        for (int i = 0; i < n; i++)
            cin >> data[i].name >> data[i].age >> data[i].score;
        sort(data, data+n, cmp);
        for (int i = 0; i < n; i++){
            cout << data[i].name << ' ' << data[i].age << ' ' << data[i].score << endl;
        }
    }
    return 0;
}

bool cmp(student_info a, student_info b){
    if (a.score != b.score)
        return a.score < b.score;
    if (strcmp(a.name, b.name) != 0)
        return strcmp(a.name, b.name) < 0;
    else
        a.age < b.age;
}
*/

//OO way
class student_info{
public:
    char name[101];
    int age;
    int score;
    bool operator < (const student_info &a) const{
    	if (score != a.score)
        	return score < a.score;
    	if (strcmp(name, a.name) != 0)
        	return strcmp(name, a.name) < 0;
    	else
        	age < a.age;
    }
    
};

int main(int argc, char const *argv[]){
    int n;
    while(cin >> n){
        student_info data[n];
        for (int i = 0; i < n; i++)
            cin >> data[i].name >> data[i].age >> data[i].score;
        sort(data, data+n);
        for (int i = 0; i < n; i++){
            cout << data[i].name << ' ' << data[i].age << ' ' << data[i].score << endl;
        }
    }
    return 0;
}
